package com.example.aacwebdemo.es2;

import com.github.javafaker.Faker;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.*;

/**
 * @author zhao.xin06679
 * @date 2021年06月08日 9:32
 */
@Document(indexName = "test_user_action_4")
public class EsBeanUserAction {

    public EsBeanUserAction(){}

    @Id
    private long id;

    //员工ID
    @Field(type = FieldType.Long)
    private Long[] staffID;

    //目标ID
    @Field(type = FieldType.Long)
    private Long accountID;

    //组织ID
    @Field(type = FieldType.Long)
    private Long[] entID;

    //部门ID
    @Field(type = FieldType.Nested)
    private Long[] sectorID;

    //业务类型(1:IM/2:VoIP/3:会议/4:日程/5:三方应用/6:其他)
    @Field(type = FieldType.Byte)
    private Byte bizType;

    //分类:(通话/发内容/会议/日程)
    @Field(type = FieldType.Byte)
    private Byte actionType;

    //时间
    @Field(type = FieldType.Date, store = true,
            format = DateFormat.custom, pattern = "yyyy-MM-dd hh:mm:ss")
    private Date startTime;

    //通话时长（秒）
    @Field(type = FieldType.Long)
    private Integer duration;

    //详细内容
    @Field(type = FieldType.Text,enabled = false,index = false,store = false)
    private String detail;

    @Field(type = FieldType.Object)
    private User o;

    @Field(type = FieldType.Object)
    private Map<String,String> m;

    @Field(type = FieldType.Object)
    private Properties p;


    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Long[] getStaffID() {
        return staffID;
    }

    public void setStaffID(Long[] staffID) {
        this.staffID = staffID;
    }

    public Long getAccountID() {
        return accountID;
    }

    public void setAccountID(Long accountID) {
        this.accountID = accountID;
    }

    public Long[] getEntID() {
        return entID;
    }

    public void setEntID(Long[] entID) {
        this.entID = entID;
    }

    public Long[] getSectorID() {
        return sectorID;
    }

    public void setSectorID(Long[] sectorID) {
        this.sectorID = sectorID;
    }

    public Byte getBizType() {
        return bizType;
    }

    public void setBizType(Byte bizType) {
        this.bizType = bizType;
    }

    public Byte getActionType() {
        return actionType;
    }

    public void setActionType(Byte actionType) {
        this.actionType = actionType;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Integer getDuration() {
        return duration;
    }

    public void setDuration(Integer duration) {
        this.duration = duration;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public User getO() {
        return o;
    }

    public void setO(User o) {
        this.o = o;
    }



    public Properties getP() {
        return p;
    }

    public void setP(Properties p) {
        this.p = p;
    }

    public Map<String, String> getM() {
        return m;
    }

    public void setM(Map<String, String> m) {
        this.m = m;
    }

    public static EsBeanUserAction build(long i){

        Faker faker = new Faker(Locale.CHINA);

        EsBeanUserAction bean = new EsBeanUserAction();
        bean.setId(i);

        bean.setStaffID(createStaffID());
        bean.setAccountID(faker.random().nextLong(20000L));
        bean.setEntID(createEntID());
        bean.setSectorID(createSectorID());
        bean.setBizType(BizType.RadmonBuild());
        bean.setActionType(ActionType.RadmonBuild());
        bean.setStartTime(new Date());
        bean.setDuration(faker.random().nextInt(1,3600));
        bean.setDetail(RadmonString.generateRandomStr(50));

        bean.setEntID(new Long[]{5172247281374565445L});
        bean.setAccountID(5172247281374565445L);

        User u = new User();
        u.setAge(100);
        u.setName("xiaoxia");

        bean.setO(u);

        Map<String,String> m = new HashMap<>();
        m.put("ma","mA");
        m.put("mb","mB");
        bean.setM(m);

        Properties p = new Properties();
        p.setProperty("pa","pA");
        p.setProperty("pb","pB");
        bean.setP(p);


        return bean;
    }


    public static Long[]  createEntID(){

        Faker faker = new Faker(Locale.CHINA);

        int size = faker.random().nextInt(0,5);
        if (size == 0){
            return null;
        }

        Long[] result = new Long[size];
        Set<Long> tmpSet = new HashSet<>();
        for (int i = 0 ; i< size;i++){

            Long tmp = null;
            do{
                tmp = faker.random().nextLong(20000L);
            }while (tmpSet.contains(tmp));
            tmpSet.add(tmp);
            result[i] = tmp;
        }
        return result;
    }

    public static Long[]  createStaffID(){

        Faker faker = new Faker(Locale.CHINA);

        int size = faker.random().nextInt(0,5);
        if (size == 0){
             return null;
        }

        Long[] result = new Long[size];
        Set<Long> tmpSet = new HashSet<>();
        for (int i = 0 ; i< size;i++){

            Long tmp = null;
            do{
                tmp = faker.random().nextLong(20000L);
            }while (tmpSet.contains(tmp));
            tmpSet.add(tmp);
            result[i] = tmp;
        }
        return result;
    }

    public static Long[] createSectorID(){

        Faker faker = new Faker(Locale.CHINA);
        int size = faker.random().nextInt(0,5);
        if (size == 0){
            return null;
        }

        Long[] result = new Long[size];
        Set<Long> tmpSet = new HashSet<>();

        for (int i = 0 ; i< size;i++){
            Long tmp = null;
            do{
                tmp = faker.random().nextLong(600);
            }while (tmpSet.contains(tmp));
            tmpSet.add(tmp);
            result[i] = tmp;
        }
        return result;
    }



}

/**
 *
 * @author zhao.xin06679
 * @date 2021/7/2 13:33
 *
 * 1:IM
 * 2:VoIP
 * 3:会议
 * 4:日程
 * 5:三方应用
 * 6:其他
 */
class BizType {

    public final static byte IM = 1;
    public final static byte VOIP = 2;
    public final static byte MEETING = 3;
    public final static byte SCHEDULE = 4;
    public final static byte THIRD_APP = 5;
    public final static byte OTHRE = 6;

    public static byte RadmonBuild(){
        Faker faker = new Faker(Locale.CHINA);
        int radmon = faker.random().nextInt(6);
        switch (radmon) {
            case 0:
                return IM;
            case 1:
                return VOIP;
            case 2:
                return MEETING;
            case 3:
                return SCHEDULE;
            case 4:
                return THIRD_APP;
            default:
                return OTHRE;

        }
    }


}


class ActionType {

    public static final int DEFAULT = 0;
    public static final int TEXT = 1;
    public static final int IMAGE = 2;
    public static final int AUDIO = 3;
    public static final int VIDEO = 4;
    public static final int IMAGE_HQ = 5;
    public static final int FILE_DOC = 6;
    public static final int FILE_PDF = 7;
    public static final int FILE_XLS = 8;
    public static final int FILE_PPT = 9;
    public static final int FILE_ZIP = 10;
    public static final int FILE_TXT = 11;
    public static final int HTML_URL = 12;
    public static final int FILE_OTHER = 13;
    public static final int SYSTEM_NOTICE = 14;
    public static final int VOIP_REMINDER = 15;
    public static final int CHAT_LOG = 16;
    public static final int LOCATION_SHARE = 17;//位置分享
    public static final int VOTE = 18;//投票
    public static final int SCHEDUAL = 19; //日程分享
    public static final int VOIP_CALL_END_REMINDER = 20;//voip通话记录消息
    public static final int AUTH_APP_SHARE = 21;


    public static byte RadmonBuild(){
        Faker faker = new Faker(Locale.CHINA);
        int radmon = faker.random().nextInt(21);
        switch (radmon) {
            case 0:
                return DEFAULT;
            case 1:
                return TEXT;
            case 2:
                return IMAGE;
            case 3:
                return AUDIO;
            case 4:
                return VIDEO;
            case 5:
                return IMAGE_HQ;
            case 6:
                return FILE_DOC;
            case 7:
                return FILE_PDF;
            case 8:
                return FILE_XLS;
            case 9:
                return FILE_PPT;
            case 10:
                return FILE_ZIP;
            case 11:
                return FILE_TXT;
            case 12:
                return HTML_URL;
            case 13:
                return FILE_OTHER;
            case 14:
                return SYSTEM_NOTICE;
            case 15:
                return VOIP_REMINDER;
            case 16:
                return CHAT_LOG;
            case 17:
                return LOCATION_SHARE;
            case 18:
                return VOTE;
            case 19:
                return SCHEDUAL;
            case 20:
                return VOIP_CALL_END_REMINDER;
            default:
                return AUTH_APP_SHARE;
        }
    }

}

class User {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

